package taskone;
import java.util.Scanner;
import java.util.Scanner;

public class taskone {

    class Queue {
        private int[] element;
        private int size;

        // 构造方法，使用默认容量 5 创建 Queue 对象
        public Queue() {
            element = new int[5];
            size = 0;
        }

        // 将 v 加入到队列中
        public void enqueue(int v) {
            if (size < element.length) {
                element[size++] = v;
            }
        }

        // 从队列中移除元素并返回该元素
        public int dequeue() {
            if (empty()) {
                return -1;
            }
            int removed = element[0];
            for (int i = 0; i < size - 1; i++) {
                element[i] = element[i + 1];
            }
            size--;
            return removed;
        }

        // 如果队列为空，返回 true
        public boolean empty() {
            return size == 0;
        }

        // 返回队列的大小
        public int getSize() {
            return size;
        }
    }

    public class QueueTest {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);

            System.out.println("请输入要入队的整数个数(<=5)");
            int n = scanner.nextInt();

            Queue queue = new Queue(); // 修正类名的大小写

            System.out.println("请依次输入" + n + "个整数");
            for (int i = 0; i < n; i++) {
                int num = scanner.nextInt();
                queue.enqueue(num);
            }

            System.out.println("请输入要出队的整数个数");
            int m = scanner.nextInt();

            System.out.println("队列开始出队");
            for (int i = 0; i < m &&!queue.empty(); i++) {
                System.out.print(queue.dequeue() + " ");
            }
            System.out.println();

            if (queue.empty()) {
                System.out.println("队列已空无法出队");
            }

            System.out.println("队列剩余元素长度为" + queue.getSize());
        }
    }

}
